﻿CREATE TABLE [CD].[DepartmentUsers] (
    [Id]           INT           NOT NULL,
    [DepartmentId] AS            ([Id]/(100000000)),
    [Login]        VARCHAR (50)  NOT NULL,
    [FirstName]    VARCHAR (50)  NULL,
    [SecondName]   VARCHAR (50)  NULL,
    [LastName]     VARCHAR (50)  NULL,
    [Note]         VARCHAR (250) NULL,
    [MD]           DATETIME      CONSTRAINT [DF__DepartmentUs__MD__0FB750B3] DEFAULT (getdate()) NOT NULL,
    [MW]           VARCHAR (50)  CONSTRAINT [DF__DepartmentUs__MW__10AB74EC] DEFAULT (suser_sname()) NOT NULL,
    CONSTRAINT [PK_DepartmentUsers] PRIMARY KEY CLUSTERED ([Id] ASC)
);


GO

CREATE TRIGGER CD.DepartmentUsersDeleteLog ON CD.DepartmentUsers AFTER DELETE
AS 
BEGIN
	SET NOCOUNT ON;

INSERT INTO [PR].[DocDeleteLog] (TableName, IdValue, MD, MW)
SELECT 'CD.DepartmentUsers', Id, getdate(), SYSTEM_USER FROM DELETED

END

GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Имя', @level0type = N'SCHEMA', @level0name = N'CD', @level1type = N'TABLE', @level1name = N'DepartmentUsers', @level2type = N'COLUMN', @level2name = N'FirstName';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Отчество', @level0type = N'SCHEMA', @level0name = N'CD', @level1type = N'TABLE', @level1name = N'DepartmentUsers', @level2type = N'COLUMN', @level2name = N'SecondName';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Фамилия', @level0type = N'SCHEMA', @level0name = N'CD', @level1type = N'TABLE', @level1name = N'DepartmentUsers', @level2type = N'COLUMN', @level2name = N'LastName';

